The basic usage of this encoder is as follows:
Unlike the decoders, the stream encoder has many options that can affect the speed and compression ratio. When setting these parameters you should have some basic knowledge of the format (see the user-level documentation or the formal description). The FLAC__stream_encoder_set_*() functions themselves do not validate the values as many are interdependent. The FLAC__stream_encoder_init() function will do this, so make sure to pay attention to the state returned by FLAC__stream_encoder_init() to make sure that it is FLAC__STREAM_ENCODER_OK. Any parameters that are not set before FLAC__stream_encoder_init() will take on the defaults from the constructor.
The user must provide function pointers for the following callbacks:
fLaC
signature, and once for each encoded metadata block.
After initializing the instance, the user may feed audio data to the encoder in one of two ways:
For programs that write their own metadata, but that do not know the actual metadata until after encoding, it is advantageous to instruct the encoder to write a PADDING block of the correct size, so that instead of rewriting the whole stream after encoding, the program can just overwrite the PADDING block. If only the maximum size of the metadata is known, the program can write a slightly larger padding block, then split it after encoding.
Make sure you understand how lengths are calculated. All FLAC metadata blocks have a 4 byte header which contains the type and length. This length does not include the 4 bytes of the header. See the format page for the specification of metadata blocks and their lengths.
true
, otherwise false
.
|
Signature for the write callback. See FLAC__stream_encoder_set_write_callback() for more info.
|
|
Signature for the metadata callback. See FLAC__stream_encoder_set_metadata_callback() for more info.
|
|
State values for a FLAC__StreamEncoder The encoder's state can be obtained by calling FLAC__stream_encoder_get_state().
|
|
Return values for the FLAC__StreamEncoder write callback. |
|
Create a new stream encoder instance. The instance is created with default settings; see the individual FLAC__stream_encoder_set_*() functions for each setting's default.
|
|
Free an encoder instance. Deletes the object pointed to by encoder.
|
|
Set the "verify" flag. If
|
|
Set the "streamable subset" flag. If
Make sure you know what it entails before setting this to
|
|
Set to
|
|
Set to
|
|
Set the number of channels to be encoded.
|
|
Set the sample resolution of the input to be encoded.
|
|
Set the sample rate (in Hz) of the input to be encoded.
|
|
Set the blocksize to use while encoding.
|
|
Set the maximum LPC order, or
|
|
Set the precision, in bits, of the quantized linear predictor coefficients, or
|
|
Set to
|
|
Deprecated. Setting this value has no effect.
|
|
Set to
|
|
Set the minimum partition order to search when coding the residual. This is used in tandem with FLAC__stream_encoder_set_max_residual_partition_order().
The partition order determines the context size in the residual. The context size will be approximately
Set both min and max values to
|
|
Set the maximum partition order to search when coding the residual. This is used in tandem with FLAC__stream_encoder_set_min_residual_partition_order().
The partition order determines the context size in the residual. The context size will be approximately
Set both min and max values to
|
|
Deprecated. Setting this value has no effect.
|
|
Set an estimate of the total samples that will be encoded. This is merely an estimate and may be set to
|
|
Set the metadata blocks to be emitted to the stream before encoding. A value of
|
|
Set the write callback. The supplied function will be called by the encoder anytime there is raw encoded data ready to write. It may include metadata mixed with encoded audio frames and the data is not guaranteed to be aligned on frame or metadata block boundaries.
The only duty of the callback is to write out the bytes worth of data in buffer to the current position in the output stream. The arguments samples and current_frame are purely informational. If samples is greater than
|
|
Set the metadata callback. The supplied function will be called once at the end of encoding with the populated STREAMINFO structure. This is so file encoders can seek back to the beginning of the file and write the STREAMINFO block with the correct statistics after encoding (like minimum/maximum frame size and total samples).
|
|
Set the client data to be passed back to callbacks. This value will be supplied to callbacks in their client_data argument.
|
|
Get the current encoder state.
|
|
Get the state of the verify stream decoder. Useful when the stream encoder state is
|
|
Get the current encoder state as a C string. This version automatically resolves
|
|
Get relevant values about the nature of a verify decoder error. Useful when the stream encoder state is
|
|
Get the "verify" flag.
|
|
Get the "streamable subset" flag.
|
|
Get the "mid/side stereo coding" flag.
|
|
Get the "adaptive mid/side switching" flag.
|
|
Get the number of input channels being processed.
|
|
Get the input sample resolution setting.
|
|
Get the input sample rate setting.
|
|
Get the blocksize setting.
|
|
Get the maximum LPC order setting.
|
|
Get the quantized linear predictor coefficient precision setting.
|
|
Get the qlp coefficient precision search flag.
|
|
Get the "escape coding" flag.
|
|
Get the exhaustive model search flag.
|
|
Get the minimum residual partition order setting.
|
|
Get maximum residual partition order setting.
|
|
Get the Rice parameter search distance setting.
|
|
Get the previously set estimate of the total samples to be encoded. The encoder merely mimics back the value given to FLAC__stream_encoder_set_total_samples_estimate() since it has no other way of knowing how many samples the user will encode.
|
|
Initialize the encoder instance. Should be called after FLAC__stream_encoder_new() and FLAC__stream_encoder_set_*() but before FLAC__stream_encoder_process() or FLAC__stream_encoder_process_interleaved(). Will set and return the encoder state, which will be FLAC__STREAM_ENCODER_OK if initialization succeeded.
The call to FLAC__stream_encoder_init() currently will also immediately call the write callback several times, once with the
|
|
Finish the encoding process. Flushes the encoding buffer, releases resources, resets the encoder settings to their defaults, and returns the encoder state to FLAC__STREAM_ENCODER_UNINITIALIZED. Note that this can generate one or more write callbacks before returning, and will generate a metadata callback. In the event of a prematurely-terminated encode, it is not strictly necessary to call this immediately before FLAC__stream_encoder_delete() but it is good practice to match every FLAC__stream_encoder_init() with a FLAC__stream_encoder_finish().
|
|
Submit data for encoding. This version allows you to supply the input data via an array of pointers, each pointer pointing to an array of samples samples representing one channel. The samples need not be block-aligned, but each channel should have the same number of samples.
|
|
Submit data for encoding. This version allows you to supply the input data where the channels are interleaved into a single array (i.e. channel0_sample0, channel1_sample0, ... , channelN_sample0, channel0_sample1, ...). The samples need not be block-aligned but they must be sample-aligned, i.e. the first value should be channel0_sample0 and the last value channelN_sampleM.
|
|
Maps a FLAC__StreamEncoderState to a C string. Using a FLAC__StreamEncoderState as the index to this array will give the string equivalent. The contents should not be modified. |
|
Maps a FLAC__StreamEncoderWriteStatus to a C string. Using a FLAC__StreamEncoderWriteStatus as the index to this array will give the string equivalent. The contents should not be modified. |